//
// Created by ub on 2020/11/1.
//
#include <iostream>
using namespace std;
const int ArSize = 8;
int sum_arr(const int *begin , const int * end);
/*int main ()
{
    int cookes[ArSize] = {1,2,4,8,16,32,64,128};
    int sum = sum_arr(cookes,cookes+ArSize);
    cout << "Total cookies eaten : "<< sum << endl;
    sum = sum_arr(cookes,cookes+3);
    cout << "First three eaters ate" << sum << "cookies.\n";
    sum = sum_arr(cookes+4,cookes+8);
    cout << "Last four eaters ate " << sum << " cookies.\n";
    return 0;
}*/
/**
 *
 * @param begin
 * @param end
 * @return
 */
int sum_arr (const int * begin ,const int * end)
{
    const int * pt;
    int total = 0;
    for (pt = begin;pt!=end;pt++)
    {
        total+=*pt;
    }
    int age = 39,sage = 99;
    const int *pt1 = &age; // 指向一个常量 即被指向的变量被修改了,指针却不会随着被指向的变量的改变而改变
    age =243;
    cout << *pt1 << endl;
    pt1 =&sage;
    cout << *pt1 << endl;

    int sloth =3;
    const int * ps = &sloth;
    int * const finger = &sloth; // 常量指针 即这个指针指向的地址不能变更了
    // finger = new int; 验证常量指针修改指向的地址
    sloth =43;
    cout << *finger << endl;
    return total;
}

void fun ()
{
  int age = 30,sloth = 89,other = 0;
  const int * pt = &age;
  age = 89;
  cout << *pt << endl;
  pt = &other;
  cout << *pt << endl;

  int * const ps = &sloth;
  sloth = other;
  cout << *ps << endl;
 // ps = &pt;
}